package com.korubo.web.contrller;

import cn.hutool.core.lang.UUID;
import com.korubo.kit.R;
import com.korubo.web.model.User;
import com.korubo.web.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (tb_user)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    //login
    @PostMapping("login")
    public R login(@RequestBody User user) {
        return userService.login(user);
    }

    //list
    @PostMapping("list")
    public R list(@RequestBody User user) {
        return userService.list(user);
    }

    @PostMapping("add")
    public R add(@RequestBody User user) {
        user.setId(UUID.fastUUID().toString());
        return userService.save(user) ? R.ok() : R.fail();
    }

    @PostMapping("update")
    public R update(@RequestBody User user) {
        return userService.updateById(user) ? R.ok() : R.fail();
    }

    @PostMapping("delete")
    public R delete(@RequestBody User user) {
        return userService.removeById(user.getId()) ? R.ok() : R.fail();
    }

    @PostMapping("findById")
    public R findById(@RequestBody User user) {
        return R.ok(userService.getById(user.getId()));
    }

}
